<?php

class ErrorController extends My_Controller_Action
{

 	public function init()
    {
        parent::init();
    }


    public function preDispatch()
    {
        $errors = $this->_getParam('error_handler');
        //        if (empty($errors->type)) {
        //	        $this->_flashMessenger 	= $this->_helper->getHelper('FlashMessenger');
        //	        //$this->_helper->redirector('index', 'index');
        //        }
    }

    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:

                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = $this->translate->translate('errors-page-not-found');
                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->message = $this->translate->translate('errors-application-error');
                break;
        }

        $this->view->exception = $errors->exception;
        $this->view->request   = $errors->request;

        /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */
        //send exception-application error alert to admins

			$siteConfig = Zend_Registry::get('siteConfig');

	        $mailer = new Default_Model_Mailer();
            $mailView = $mailer->getMailView();

	        $mailView->message 	 = $this->view->message;
	        $mailView->exception = $errors->exception;
	        $mailView->request   = $errors->request;
	        $mailView->authdata  = $this->view->authdata;

			$bodyText  = $mailView->render('alert.error.phtml');
			//$bodyText .= $mailView->render('signature.phtml');
			//echo $bodyText; exit;

			$mailData['to'] 		= $siteConfig->emails->admin->email;
			$mailData['toLabel'] 	= $siteConfig->emails->admin->label;
			$mailData['from'] 		= $siteConfig->emails->from->email;
			$mailData['fromLabel'] 	= $siteConfig->emails->from->label;
			$mailData['subject'] 	= $this->translate->translate('errors-mail-subject-alert-error-occurred!');
			$mailData['body'] 		= $bodyText;
			$mailData['mailBodyType'] 	= 'html';

			$mailer->send($mailData);
			unset($bodyText);
			unset($mailData);
			unset($mailer);
        /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */

    }

    public function deniedAction()
    {
        // action body
    }

    public function blockedAction()
    {
        // action body
    }

    public function testAction()
    {
        // action body
    }


}


